//
//  CTGenRequestData.m
//  ConstellationTalk_0.1
//
//  Created by riley on 15/6/1.
//  Copyright (c) 2015年 riley chu. All rights reserved.
//

#import "CTGenRequestData.h"
#import "CTAppLanguage.h"
#import "CTLogin.h"
#import "CTDeviceFunction.h"
#import "CRSA.h"
#import "CTUser.h"
#import "CTUserItem.h"
#import "CTDebugManager.h"



@implementation CTGenRequestData


#pragma mark - login -

+(CTMobileLoginRequestItem *)genMobileLoginRequestItemUserName:(NSString *)name withPassword:(NSString *)passwordStr
{
    CTMobileLoginRequestItem * reitem = [[CTMobileLoginRequestItem alloc] init];
    
    reitem.mobile = name;
    reitem.cipher = [[CRSA shareInstance] encryptByRsa:passwordStr withKeyType:KeyTypePublic];
    reitem.openid = [[CRSA shareInstance] encryptByRsa:[CTDeviceFunction DeviceUDID] withKeyType:KeyTypePublic];
    reitem.deviceid = [CTDeviceFunction DeviceUDID];
    reitem.clienttime = [CTDeviceFunction UnixTimestamp];
    
    
    
    return reitem;
}

+(CTMobileRegisterRequestItem *)genMobileRegisterRequestItemUserName:(NSString *)name
                                                        withPassword:(NSString *)passwordStr
                                                     withPhoneNumber:(NSString *)number
                                                          withGender:(NSString *)gender
                                                         withHeadImg:(UIImage *)headImg
{
    CTMobileRegisterRequestItem * itm = [[CTMobileRegisterRequestItem alloc] init];
    
    NSString * languageStr = [CTAppLanguage systemLanguage];
    itm.mobile = number;
    itm.head = UIImageJPEGRepresentation(headImg, 1.0);
    itm.cipher = [[CRSA shareInstance] encryptByRsa:passwordStr withKeyType:KeyTypePublic];
    itm.openid = [[CRSA shareInstance] encryptByRsa:[CTDeviceFunction DeviceUDID] withKeyType:KeyTypePublic];
    itm.deviceid = [CTDeviceFunction DeviceUDID];
    itm.clienttime = [CTDeviceFunction UnixTimestamp];
    itm.channel = @"appStore";
    itm.name = name;
    if ([languageStr isEqualToString:@"zh-Hans"])itm.lang = @"cn";
    else itm.lang = @"en";
    if ([gender isEqualToString:@"男"]) {
        itm.gender = @"1";
    }else if ([gender isEqualToString:@"女"]){
        itm.gender = @"2";
    }else{
        itm.gender = @"0";
    }
    
    return itm;
}

+(CTRestPasswordRequestItem *)genRestPasswordRequestItemPhoneNumber:(NSString *)number
                                                       withPassword:(NSString *)passwordStr
{
    CTRestPasswordRequestItem * item = [[CTRestPasswordRequestItem alloc] init];
    item.mobile = [[CRSA shareInstance] encryptByRsa:number withKeyType:KeyTypePublic];
    item.cipher = [[CRSA shareInstance] encryptByRsa:passwordStr withKeyType:KeyTypePublic];
    
    return item;
}
+(CTVerificationRequestItem *)genVerificationRequestItemPhoneNumber:(NSString *)number
{
    CTVerificationRequestItem * item = [[CTVerificationRequestItem alloc] init];
    item.mobile = [[CRSA shareInstance] encryptByRsa:number withKeyType:KeyTypePublic];
    
    return item;
}

+(CTThirdPartyLoginRequestItem *)genTPItemInfo:(NSDictionary *)info withType:(NSInteger)loginType
{
    
    CTThirdPartyLoginRequestItem * itm;
    @try {
        
        itm = [[CTThirdPartyLoginRequestItem alloc] init];
        
        NSString * languageStr = [CTAppLanguage systemLanguage];
        itm.openid = [[CRSA shareInstance] encryptByRsa:[CTDeviceFunction DeviceUDID] withKeyType:KeyTypePublic];
        itm.deviceid = [CTDeviceFunction DeviceUDID];
        itm.clienttime = [CTDeviceFunction UnixTimestamp];
        if ([languageStr isEqualToString:@"zh-Hans"])itm.lang = @"cn";
        else itm.lang = @"en";
        itm.channel = @"appStore";
        
        
        switch (loginType) {
            case 1:
                itm.identification = [NSString stringWithFormat:@"%@",[info objectForKey:@"idstr"]];
                itm.name = [NSString stringWithFormat:@"%@",[info objectForKey:@"name"]];
                itm.head = [NSString stringWithFormat:@"%@",[info objectForKey:@"avatar_large"]];
                if ([[NSString stringWithFormat:@"%@",[info objectForKey:@"gender"]] isEqualToString:@"m"]) {
                    itm.gender = @"1";
                }else if([[NSString stringWithFormat:@"%@",[info objectForKey:@"gender"]] isEqualToString:@"f"]){
                    itm.gender = @"2";
                }else{
                    itm.gender = @"0";
                }
                
                break;
            case 2:
                itm.identification = [NSString stringWithFormat:@"%@",[info objectForKey:@"uid"]];
                itm.name = [NSString stringWithFormat:@"%@",[info objectForKey:@"nickname"]];
                itm.head = [NSString stringWithFormat:@"%@",[info objectForKey:@"figureurl_qq_2"]];
                if ([[NSString stringWithFormat:@"%@",[info objectForKey:@"gender"]] isEqualToString:@"男"]) {
                    itm.gender = @"1";
                }else if([[NSString stringWithFormat:@"%@",[info objectForKey:@"gender"]] isEqualToString:@"女"]){
                    itm.gender = @"2";
                }else{
                    itm.gender = @"0";
                }
                break;
            case 3:
                itm.identification = [NSString stringWithFormat:@"%@",[info objectForKey:@"unionid"]];
                itm.name = [NSString stringWithFormat:@"%@",[info objectForKey:@"nickname"]];
                itm.head = [NSString stringWithFormat:@"%@",[info objectForKey:@"headimgurl"]];
                if ([[NSString stringWithFormat:@"%@",[info objectForKey:@"sex"]] isEqualToString:@"1"]) {
                    itm.gender = @"1";
                }else if([[NSString stringWithFormat:@"%@",[info objectForKey:@"sex"]] isEqualToString:@"2"]){
                    itm.gender = @"2";
                }else{
                    itm.gender = @"0";
                }
                break;
            
            default:
                break;
        }
    }
    @catch (NSException *exception) {
        [CTDebugManager showErrorLogInfo:@"组装第三方授权数据失败！！"];
    }
    
    
    return itm;
}



#pragma mark - publish -

+(CTRequestEditeEmojiListItem *)genRequestEditeEmojiListItem
{
    NSString * languageStr = [CTAppLanguage systemLanguage];
    
    CTRequestEditeEmojiListItem * item = [[CTRequestEditeEmojiListItem alloc] init];
    item.token = [CTLogin token];
    if ([CTLogin isUserLoginState] == NO)item.visitor = @"visitor";
    else item.visitor = @"user";
    if ([languageStr isEqualToString:@"zh-Hans"])item.lang = @"cn";
    else item.lang = @"en";
    item.count = @"100";
    item.page = @"0";
    return item;
}

+(CTRequestEditeBubbleListItem *)genRequestEditeBubbleListItem
{
    NSString * languageStr = [CTAppLanguage systemLanguage];
    
    CTRequestEditeBubbleListItem * item = [[CTRequestEditeBubbleListItem alloc] init];
    item.token = [CTLogin token];
    if ([CTLogin isUserLoginState] == NO)item.visitor = @"visitor";
    else item.visitor = @"user";
    if ([languageStr isEqualToString:@"zh-Hans"])item.lang = @"cn";
    else item.lang = @"en";
    return item;
}

+(CTRequestPublishUploadItem *)genRequestPublishUpadteItem:(UIImage *)pic content:(NSString *)contentStr withGroup:(NSString *)groupStr
{
    NSString * languageStr = [CTAppLanguage systemLanguage];
    
    CTRequestPublishUploadItem * item = [[CTRequestPublishUploadItem alloc] init];
    item.token = [CTLogin token];
    item.text = contentStr;
    if ([languageStr isEqualToString:@"zh-Hans"])item.lang = @"cn";
    else item.lang = @"en";
    item.pic = pic;
    item.group = groupStr;
    
    return item;
}


#pragma mark - home page -

+(CTRequestHotSpotsItem *)genRequestHotSpotsItem
{
    NSString * languageStr = [CTAppLanguage systemLanguage];
    
    CTRequestHotSpotsItem * item = [[CTRequestHotSpotsItem alloc] init];
    item.token = [CTLogin token];
    if ([CTLogin isUserLoginState] == NO)item.visitor = @"visitor";
    else item.visitor = @"user";
    if ([languageStr isEqualToString:@"zh-Hans"])item.lang = @"cn";
    else item.lang = @"en";
    item.count = @"100";
    item.timelimit = [CTDeviceFunction UnixTimestamp];
    item.page = @"0";
    return item;
}
+(CTRequestHotSpotsDetailItem *)genRequestHotSpotsDetailItem:(CTHotSpotsItem *)itm withFilpNumber:(NSInteger)count
{
    NSString * languageStr = [CTAppLanguage systemLanguage];
    
    CTRequestHotSpotsDetailItem * item = [[CTRequestHotSpotsDetailItem alloc] init];
    item.token = [CTLogin token];
    if ([CTLogin isUserLoginState] == NO)item.visitor = @"visitor";
    else item.visitor = @"user";
    if ([languageStr isEqualToString:@"zh-Hans"])item.lang = @"cn";
    else item.lang = @"en";
    item.count = [NSString stringWithFormat:@"%ld",(long)10*count];
    item.timelimit = [CTDeviceFunction UnixTimestamp];
    item.page = @"0";
    item.like_num = @"8";
    item.comment_num = @"2";
    item.group_id = itm.group_id;
    
    
    return item;
}
+(CTRequestSubjectItem *)genRequestSubjectItem:(CTHotSpotsItem *)itm
{
    NSString * languageStr = [CTAppLanguage systemLanguage];
    
    CTRequestSubjectItem * item = [[CTRequestSubjectItem alloc] init];
    item.token = [CTLogin token];
    if ([CTLogin isUserLoginState] == NO)item.visitor = @"visitor";
    else item.visitor = @"user";
    if ([languageStr isEqualToString:@"zh-Hans"])item.lang = @"cn";
    else item.lang = @"en";
    item.group_id = itm.group_id;
    
    
    return item;
}




#pragma mark - discovery -



+(CTRequestFollowList *)genRequestFollowListWithFilpNumber:(NSInteger)count
{
    
    NSString * languageStr = [CTAppLanguage systemLanguage];
    CTRequestFollowList* item = [[CTRequestFollowList alloc] init];
    
    if ([CTLogin isUserLoginState] == YES) {
        CTUserItem * userItm = [CTUser userInfo];
        if ([userItm.followers_count isEqualToString:@"0"]) {
            item.token = [CTLogin token];
            if ([languageStr isEqualToString:@"zh-Hans"])item.lang = @"cn";
            else item.lang = @"en";
            item.visitor = @"user";
            item.like_num = @"8";
            item.comment_num = @"2";
        }else{
            item.token = [CTLogin token];
            item.timelimit = [CTDeviceFunction UnixTimestamp];
            if ([languageStr isEqualToString:@"zh-Hans"])item.lang = @"cn";
            else item.lang = @"en";
            item.count = [NSString stringWithFormat:@"%ld",(long)10*count];
            item.page = @"0";
            item.like_num = @"8";
            item.comment_num = @"2";
        }
    }else{
        item.token = [CTLogin token];
        if ([languageStr isEqualToString:@"zh-Hans"])item.lang = @"cn";
        else item.lang = @"en";
        if ([CTLogin isUserLoginState] == NO)item.visitor = @"visitor";
        else item.visitor = @"user";
        item.like_num = @"8";
        item.comment_num = @"2";
    }
    
    return item;
}

+(CTRequestUserSuggestionItem *)genRequestUserSuggestionItem
{
    NSString * languageStr = [CTAppLanguage systemLanguage];
    
    CTRequestUserSuggestionItem * item = [[CTRequestUserSuggestionItem alloc] init];
    item.token = [CTLogin token];
    if ([CTLogin isUserLoginState] == NO)item.visitor = @"visitor";
    else item.visitor = @"user";
    if ([languageStr isEqualToString:@"zh-Hans"])item.lang = @"cn";
    else item.lang = @"en";
    item.count = @"1";
    
    return item;
}





#pragma mark - message -

+(CTRequestMessageListItem *)genRequestMessageListItemWithFlipNumber:(NSInteger)count
{
    NSString * languageStr = [CTAppLanguage systemLanguage];
   
    CTRequestMessageListItem * itm = [[CTRequestMessageListItem alloc] init];
    itm.token = [CTLogin token];
    if ([languageStr isEqualToString:@"zh-Hans"])itm.lang = @"cn";
    else itm.lang = @"en";
    itm.count = [NSString stringWithFormat:@"%ld",(long)10*count];
    itm.page = @"0";
    itm.timelimit = [CTDeviceFunction UnixTimestamp];
    
    return itm;
}
+(CTRequestMessageDeleteItem *)genRequestMessageDeleteItem:(CTMessageListItem *)item
{
    CTRequestMessageDeleteItem * itm = [[CTRequestMessageDeleteItem alloc] init];
    itm.token = [CTLogin token];
    itm.notice_id = item.notice_id;
    
    return itm;
}

+(CTRequestMessageSwitchItem *)genRequestMessageSwitchItem:(NSString *)switchFlag
{
    CTRequestMessageSwitchItem * itm = [[CTRequestMessageSwitchItem alloc] init];
    itm.token = [CTLogin token];
    itm.close = switchFlag;
    
    return itm;
}






#pragma mark - user -

+(CTUserInfoModifyRequestItem *)genUserInfoModifyRequestItemUserName:(NSString *)name
                                                         withHeadImg:(UIImage *)headImg
{
    NSString * languageStr = [CTAppLanguage systemLanguage];
    CTUserItem * userInfo = [CTUser userInfo];
    
    CTUserInfoModifyRequestItem * itm = [[CTUserInfoModifyRequestItem alloc] init];
    itm.name = name;
    if ([languageStr isEqualToString:@"zh-Hans"])itm.lang = @"cn";
    else itm.lang = @"en";
    itm.head = UIImageJPEGRepresentation(headImg, 1.0);
    itm.token = [CTLogin token];
    itm.sign = userInfo.sign;
    
    return itm;
}

+(CTUserRequestItem *)genUserRequestItem:(NSString *)userID
{
    NSString * languageStr = [CTAppLanguage systemLanguage];
  
    CTUserRequestItem * itm = [[CTUserRequestItem alloc] init];
    if ([languageStr isEqualToString:@"zh-Hans"])itm.lang = @"cn";
    else itm.lang = @"en";
    itm.token = [CTLogin token];
    itm.uid = userID;
    if ([CTLogin isUserLoginState] == NO)itm.visitor = @"visitor";
    else itm.visitor = @"user";
    
    return itm;
}


+(CTRequestFenceUserItem *)genRequestFenceUserItem:(NSString *)userID
{
    NSString * languageStr = [CTAppLanguage systemLanguage];
    
    CTRequestFenceUserItem * itm = [[CTRequestFenceUserItem alloc] init];
    itm.token = [CTLogin token];
    if ([languageStr isEqualToString:@"zh-Hans"])itm.lang = @"cn";
    else itm.lang = @"en";
    itm.uid = userID;
    itm.count = @"1000";
    itm.page = @"0";
    if ([CTLogin isUserLoginState] == NO)itm.visitor = @"visitor";
    else itm.visitor = @"user";
    itm.timelimit = [CTDeviceFunction UnixTimestamp];
    
    return itm;
}
+(CTRequestFollowUserItem *)genRequestFollowUserItem:(NSString *)userID
{
    NSString * languageStr = [CTAppLanguage systemLanguage];
    
    
    CTRequestFollowUserItem * itm = [[CTRequestFollowUserItem alloc] init];
    itm.token = [CTLogin token];
    if ([languageStr isEqualToString:@"zh-Hans"])itm.lang = @"cn";
    else itm.lang = @"en";
    itm.uid = userID;
    itm.count = @"1000";
    itm.page = @"0";
    if ([CTLogin isUserLoginState] == NO)itm.visitor = @"visitor";
    else itm.visitor = @"user";
    itm.timelimit = [CTDeviceFunction UnixTimestamp];
    
    return itm;
}

+(CTRequestUserPublishDetailListItem *)genRequestUserPublishDetailListItem:(NSString *)userID withFlipNumber:(NSInteger)count
{
    NSString * languageStr = [CTAppLanguage systemLanguage];
    
    CTRequestUserPublishDetailListItem * itm = [[CTRequestUserPublishDetailListItem alloc] init];
    itm.token = [CTLogin token];
    if ([languageStr isEqualToString:@"zh-Hans"])itm.lang = @"cn";
    else itm.lang = @"en";
    itm.uid = userID;
    itm.count = [NSString stringWithFormat:@"%ld",(long)10*count];
    itm.page = @"0";
    if ([CTLogin isUserLoginState] == NO)itm.visitor = @"visitor";
    else itm.visitor = @"user";
    itm.timelimit = [CTDeviceFunction UnixTimestamp];
    itm.like_num = @"8";
    itm.comment_num = @"2";
    
    return itm;
}



#pragma mark - other (关注，点赞，举报....) -


+(CTRequestFollowPseronItem *)genRequestFollowPseronItem:(NSString *)uid
{
    NSString * languageStr = [CTAppLanguage systemLanguage];
   
    CTRequestFollowPseronItem * itm = [[CTRequestFollowPseronItem alloc] init];
    itm.token = [CTLogin token];
    if ([languageStr isEqualToString:@"zh-Hans"])itm.lang = @"cn";
    else itm.lang = @"en";
    itm.uid = uid;
   
    
    return itm;
}
+(CTRequestCancelFollowPseronItem *)genRequestCancelFollowPseronItem:(NSString *)uid
{
    NSString * languageStr = [CTAppLanguage systemLanguage];
    
    CTRequestCancelFollowPseronItem* itm = [[CTRequestCancelFollowPseronItem alloc] init];
    itm.token = [CTLogin token];
    if ([languageStr isEqualToString:@"zh-Hans"])itm.lang = @"cn";
    else itm.lang = @"en";
    itm.uid = uid;
    
    
    return itm;
}

+(CTRequestLikePseronItem *)genRequestLikePseronItem:(NSString *)schemeID
{
    CTRequestLikePseronItem * itm = [[CTRequestLikePseronItem alloc] init];
    itm.token = [CTLogin token];
    itm.scheme_id = schemeID;
    
    return itm;
}
+(CTRequestCancelLikePseronItem *)genRequestCancelLikePseronItem:(NSString *)schemeID
{
    CTRequestCancelLikePseronItem * itm = [[CTRequestCancelLikePseronItem alloc] init];
    itm.token = [CTLogin token];
    itm.scheme_id = schemeID;
    
    return itm;
}

+(CTRequestCommentItem *)genRequestCommentItem:(NSString *)schemeID 
                                   withContent:(NSString *)text
{
    NSString * languageStr = [CTAppLanguage systemLanguage];
    
    CTRequestCommentItem * itm = [[CTRequestCommentItem alloc] init];
    itm.token = [CTLogin token];
    itm.scheme_id = schemeID;
    itm.text = text;
    if ([languageStr isEqualToString:@"zh-Hans"])itm.lang = @"cn";
    else itm.lang = @"en";
    
    return itm;
}
+(CTRequestCancelCommentItem *)genRequestCancelCommentItem:(NSString *)commentID
{
    CTRequestCancelCommentItem * itm = [[CTRequestCancelCommentItem alloc] init];
    itm.token = [CTLogin token];
    itm.comment_id = commentID;
    
    return itm;
}

+(CTRequestCommentListItems *)genRequestCommentListItems:(NSString *)schemeID withFlipNumber:(NSInteger)count
{
    NSString * languageStr = [CTAppLanguage systemLanguage];
    
    CTRequestCommentListItems * itm = [[CTRequestCommentListItems alloc] init];
    itm.token = [CTLogin token];
    itm.scheme_id = schemeID;
    if ([languageStr isEqualToString:@"zh-Hans"])itm.lang = @"cn";
    else itm.lang = @"en";
    itm.count = [NSString stringWithFormat:@"%ld",(long)10*count];
    itm.timelimit = [CTDeviceFunction UnixTimestamp];
    itm.page = @"0";
    
    return itm;
}

+(CTRequestReportItem *)genRequestReportItem:(NSString *)schemeID
{
    CTRequestReportItem * itm = [[CTRequestReportItem alloc] init];
    itm.token = [CTLogin token];
    itm.scheme_id = schemeID;
    
    return itm;
}

+(CTRequestDeletePublishItem *)genRequestDeletePublishItem:(NSString *)schemeID
{
    CTRequestDeletePublishItem * itm = [[CTRequestDeletePublishItem alloc] init];
    itm.token = [CTLogin token];
    itm.scheme_id = schemeID;
    
    return itm;
}

+(CTRequestPublishDetailsInfoItem *)genRequestPublishDetailsInfoItem:(NSString *)schemeID
{
    NSString * languageStr = [CTAppLanguage systemLanguage];
    
    CTRequestPublishDetailsInfoItem * itm = [[CTRequestPublishDetailsInfoItem alloc] init];
    itm.token = [CTLogin token];
    itm.scheme_id = schemeID;
    if ([languageStr isEqualToString:@"zh-Hans"])itm.lang = @"cn";
    else itm.lang = @"en";
    if ([CTLogin isUserLoginState] == NO)itm.visitor = @"visitor";
    else itm.visitor = @"user";
    itm.like_num = @"8";
    itm.comment_num = @"2";
    
    return itm;
}


@end
